package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 */
@Configuration
public class RabbitMQConfig_WorkQueue {

    public static final String Exchange_Direct_WorkQueue = "Exchange_Direct_WorkQueue";

    public static final String Queue_WorkQueue = "Queue_WorkQueue";

    public static final String RoutingKey_WorkQueue = "RoutingKey_WorkQueue";

    @Bean(Exchange_Direct_WorkQueue)
    public Exchange Exchange_Direct_WorkQueue(){
        //durable:是否持久化
        return ExchangeBuilder.directExchange(Exchange_Direct_WorkQueue).durable(true).build();
    }

    @Bean(Queue_WorkQueue)
    public Queue Queue_Reliable(){
        //durable:是否持久化
        return QueueBuilder.durable(Queue_WorkQueue).build();
    }

    @Bean("binding_direct_workqueue")
    public Binding binding_direct_workqueue(
            @Qualifier(Queue_WorkQueue) Queue queue,
            @Qualifier(Exchange_Direct_WorkQueue) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(RoutingKey_WorkQueue).noargs();
    }
}
